import { jsx as _jsx } from "react/jsx-runtime";
import { Modal } from 'antd';
import { useRef } from 'react';
import CustomForm from '../customForm';
const CustomModal = (props) => {
    const { width = 500, visible, cancel, title, callback, configs, initialValues, layout, className, onChange } = props;
    const formRef = useRef();
    const onCancel = () => {
        cancel && cancel();
    };
    const submit = async () => {
        const { current: { validateFields } } = formRef;
        try {
            if (validateFields) {
                const values = await validateFields();
                callback && (await callback(values));
                cancel && cancel();
            }
        }
        catch (err) {
            console.log(err, 'error');
        }
    };
    return (_jsx(Modal, { title: title, visible: visible, onCancel: onCancel, onOk: submit, width: width, centered: true, maskClosable: false, className: className, children: _jsx(CustomForm, { configs: configs, ref: formRef, initialValues: initialValues, layout: layout, onChange: onChange }) }));
};
export default CustomModal;
